package com.example.androidmainshixun.adapter;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.example.androidmainshixun.view.FirstFragment;
import com.example.androidmainshixun.view.Title0Fragment;
import com.example.androidmainshixun.view.Title1Fragment;
import com.example.androidmainshixun.view.Title2Fragment;
import com.example.androidmainshixun.view.Title3Fragment;

import java.util.List;

public class SectionsPagerAdapter extends FragmentPagerAdapter {
    private List<Fragment> fragmentList;
    private List<String> titleList;

    public SectionsPagerAdapter(FragmentManager fm, List<Fragment> fragments, List<String> titles) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        this.fragmentList = fragments;
        this.titleList = titles;
    }

    @Override
    public Fragment getItem(int position) {
        // 根据position返回不同的Fragment实例
        switch (position) {
            case 0:
                return new Title0Fragment(); // 推荐
            case 1:
               return new Title1Fragment(); // 水果蔬菜
            case 2:
                return new Title2Fragment(); // 米面粮油
            case 3:
                return new Title3Fragment(); // 农资农具
            default:
                return null;
        }
    }

    @Override
    public int getCount() {
        return 4; // 标签的数量
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        // 返回TabItem的标题
        switch (position) {

            case 0:
                return "推荐";
            case 1:
                return "水果蔬菜";
            case 2:
                return "米面粮油";
            case 3:
                return "农资农具";
            default:
                return null;
        }
    }
}
